import java.io.PrintWriter;
import java.util.*;
public class Driver {
	public static void main(String[] args){
		String classLabel="Driver:";
		Scanner inFile=null;
		PQ theQ = new PQ();
		ProcessRecord rec=null;
		inFile=FileUtils.ScannerOpen("zin1");
		FileUtils.setLogFile("zlog1");
		
		//reads the process records and inserts them into priority queue
		while(inFile.hasNext()){
			rec = new ProcessRecord();
			rec = rec.readProcessRecord(inFile);
			theQ.insert(rec);
			FileUtils.logFile.println("Inserted record' "+ rec.toString());
			if(theQ.checkHeap()){
				FileUtils.logFile.println(classLabel+" Heap checks out ok");

			}
			else{
				FileUtils.logFile.println(classLabel+" Heap is not correct'  ");

			}
		}
		FileUtils.logFile.printf("The Q of %d items is%n%s%n",
				theQ.getSize(), theQ.toString());
		
		//removes records and prints them to outFile
		String s="";
		while(theQ.getSize() > 0){
			FileUtils.logFile.println("\nThe Q of "+theQ.getSize()+" items one at a time");
		
		rec = theQ.removeMax();
		s+=rec.toString()+"\n";
		FileUtils.logFile.println("Item "+ rec.toString());
	}
		FileUtils.logFile.println("\nThe sorted priority queue is \n"+s);
		FileUtils.logFile.println(classLabel+" no more data, terminate");
		FileUtils.logFile.flush();
}
}